package com.polysoft.demo.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.polysoft.demo.model.UserBO;
import com.polysoft.demo.service.IUserService;

@Controller
@RequestMapping("/user")
public class UserController {

	@Resource
	private IUserService userService;

	@RequestMapping("/showUser")
	public String toIndex(HttpServletRequest request, Model model) {
		int userId = Integer.parseInt(request.getParameter("id"));
		UserBO user = this.userService.getUserById(userId);
		model.addAttribute("user", user);
		return "User";
	}
	
	@RequestMapping("/list")
	public String findList(Model model,@RequestParam(required=true,defaultValue="1") Integer page,  
            @RequestParam(required=false,defaultValue="10") Integer pageSize) {
		PageHelper.startPage(page, pageSize);
		List<UserBO> list = userService.findList();
		PageInfo<UserBO> p = new PageInfo<UserBO>(list); 
		model.addAttribute("userList", list);
		model.addAttribute("pagehelper", p);
		return "userList";
	}
}
